﻿Public Class FrmPropertyQueryBill

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles ButtonX1.Click
        Try
            GroupBox2.Text = "查询列表(双击查看,共0行数据)"
            Dim TmpArr As Byte() = Nothing
            Dim ErrString As String = String.Empty
            Dim ds As New DataSet
            Dim FStyle As String = String.Empty
            If CheckBox1.Checked Then
                FStyle = "CN"
            Else
                FStyle = "CNZF"
            End If
            If CheckBox2.Checked Then
                FStyle = FStyle.Replace("CN", "*")
            End If
            DataGridView1.DataSource = Nothing
            If SControl._BILL_Prop_GetBillList(UInfo.FSession, DateTimePicker1.Value, DateTimePicker2.Value, TextBox1.Text.Trim, FStyle, TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox(String.Format("查询失败{0}错误信息:无法解析返回数据!", vbCrLf))
                Return
            End If
            DataGridView1.DataSource = ds.Tables(0).DefaultView
            DataGridView1.Columns(0).Visible = False
            GroupBox2.Text = String.Format("查询列表(双击查看,共{0}行数据)", ds.Tables(0).Rows.Count)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles ButtonX2.Click
        FControl.ExpertToXls(DataGridView1)
    End Sub

    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles ButtonX3.Click
        Dispose()
    End Sub

    Private Sub DataGridView1_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        If DataGridView1.SelectedCells.Count < 1 Then
            Return
        End If
        Try
            Dim sid As Integer = DataGridView1.Item(0, e.RowIndex).Value
            If sid = Nothing Then
                Return
            End If
            Dim f1 As New FrmPropertyBill With {.FBid = sid, .FOpenType = "View"}
            f1.ShowDialog()
            f1 = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ButtonX5_Click(sender As Object, e As EventArgs)
        If DataGridView1.SelectedCells.Count < 1 Then
            MsgBox("必须选择一张单据!")
            Return
        End If
        Try
            Dim sid As Integer = DataGridView1.Item(0, DataGridView1.SelectedCells(0).RowIndex).Value
            If sid = Nothing Then
                Return
            End If
            Dim f1 As New FrmPropertyBill With {.FBid = sid, .FOpenType = "Modify"}
            f1.ShowDialog()
            f1 = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles ButtonX4.Click
        Try
            Dim sid As Integer = DataGridView1.Item(0, DataGridView1.SelectedCells(0).RowIndex).Value
            If sid = Nothing Then
                Return
            End If
            Dim ErrString As String = String.Empty
            If SControl._Bill_Prop_BillCancel(UInfo.FSession, sid, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            MsgBox("作废成功!列表在重新点击查询后生效")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class